# FEEDBACK LOOPS
# Yannis K.
from collections import defaultdict

INPUT = "RegulationTwoColumnTable_Documented_2013927.tsv"
data = defaultdict(set)
dic = defaultdict(set)
with open(INPUT) as inf:
		for line in inf:
			a,b = line.rstrip().split(";")
			if a != b:          # no self-loops
				data[a].add(b)
				dic[a].add(b)

found = []
for a,bz in data.items():
	#binter = bz.intersection
	for b in bz:
		for c in dic[b]:
			if a in dic[c]:
				found.append("{} {} {}".format(a, b, c))
			

print(len(found)/3)
#print(got)
